<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
        <title>Coursity.net</title>
        <script type="text/javascript" src="js/jquery-1.9.1.min.js"></script>
        <script type="text/javascript" src="js/global.js"></script>
        <script type="text/javascript" src="js/adress_bar.js"></script>
        <style> 
            .list li{display:inline; padding-right:30px; line-height: 30px;}
            div[class="rating_item"]{padding:10px;}
            div[class="rating_item"]:hover{border-left:1px dashed #000; background-color:#CCC;}
            #search_courses{}
            #search_warning{color:#FF0000; font-weight:bold;}
        </style>
        <script>
            
            function get_user_main(){
                
                $.post('data/user_main.jsp', {}, function(result){
                    if(!result.status){
                        alert(result.error);
                    }
                    else{
                        var rh = '<h2>Rating History</h2>'; // rating_history
                        $('#official_name').find('h1').html(result.set[0].official_name);
                        if(result.set[0].rating_history.length>0){
                            for(var i=0; i<result.set[0].rating_history.length; i++){
                                rh += '<div class="rating_item">';
                                rh += '<h3>' + result.set[0].rating_history[i].course_name + '</h3>';
                                rh += '<p>' + result.set[0].rating_history[i].course_description + '</p>';
                                rh += '<b>Your rating: ' + result.set[0].rating_history[i].rating_casted + '</b>';
                                if(result.set[0].rating_history[i].comments_made.length>0){
                                    rh += '<h4>Your comments</h4><ul>';
                                    for(var j=0; j<result.set[0].rating_history[i].comments_made.length; j++){
                                        rh += '<li>' + result.set[0].rating_history[i].comments_made[j].comment_text + '</li>';
                                    }
                                    rh += '</ul>';
                                }
                                else{
                                    rh += '<p>You have no comment for this course. <a href="#">Click here to make one</a></p>';
                                }
                                rh += '</div>';
                            }
                        }
                        else{
                            rh = '<p>No rating history.</p>';
                        }
                        $('#rating_history').html(rh);
                    } 
                }, 'json')  
            }

            $(document).ready(function(){
                
                get_tags('cloud_of_tags');
                get_user_main();
                
                $('#search_courses').keyup(function(){
                    if($(this).val().length>3){
                        $('#search_warning').html('Loading...');
                        var search_string = $('#search_string').val();
                        var sr = '' // search results
                        $.post('data/course_search_list', {search_string:search_string}, function(result){
                            if(!result.status){
                                sr = 'Technical failure, sorry!';
                            }
                            else{
                                sr = 'Buraya sonuçları basıyoruz.';
                            }
                        }, 'json');
                        
                        $('#search_warning').html(sr);
                        
                        $('#search_results').html('');
                    }
                    else{
                        $('#search_warning').html('(Too short to search: '+$(this).val().length+')');
                        $('#search_results').html('');
                    }
                });
                
                
            });
        </script>
    </head>
    <body>
        <div align="right"><a href="index.html">logout (x)</a></div>
        <div id="official_name"><h1></h1></div>
        <div>Search for Courses: <input id="search_string" type="text" value="">&nbsp;<span id="search_warning"></span> Or you can just go to <a href="#">detailed search page</a></div>
        <div id="search_results"></div>
        <hr />
        <div id="rating_history"></div>
        <hr />
        <h2>Cloud of Tags</h2>        
        <div id="cloud_of_tags" class="list"></div>
    </body>
</html>